using HKB.Common;
using System;
using System.Collections;
using System.Data;
using System.Web;
namespace HKB.Web
{
	public class PayOnline
	{
		private Conn conn;
		public PayOnline()
		{
			this.conn = Text.GetComponent<Conn>("conn", HttpContext.Current.CurrentHandler);
		}
		public PayOnline(Conn _conn)
		{
			this.conn = _conn;
		}
		public DataTable Getall()
		{
			return this.conn.GetDataTable("Select *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline Order By OnlinePayID Desc");
		}
		public DataTable GetByID(int ID)
		{
			return this.conn.GetDataTable("Select *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline Where OnlinePayID=" + ID);
		}
		public DataTable GetByUserID(int UserID)
		{
			return this.conn.GetDataTable("Select *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline Where UserID=" + UserID + " Order By OnlinePayID Desc");
		}
		public DataTable GetBySQL(string wheresql, params IDbDataParameter[] param)
		{
			DataTable dataTable;
			if (param != null)
			{
				dataTable = this.conn.GetDataTable("Select *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline " + wheresql + " Order By OnlinePayID Desc", param);
			}
			else
			{
				dataTable = this.conn.GetDataTable("Select *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline " + wheresql + " Order By OnlinePayID Desc");
			}
			return dataTable;
		}
		public bool Add(int UserID, string UserName, int OrderID, string PayNum, int eBankID, decimal PayMoney, decimal PayMoneyTrue, string eBankInfo, string Remark)
		{
			string commandText = "INSERT INTO [HL_PayOnline](UserID,UserName,OrderID,PayNum,eBankID,PayMoney,PayMoneyTrue,eBankInfo,Remark,PayTime,PayStatus) VALUES(@UserID,@UserName,@OrderID,@PayNum,@eBankID,@PayMoney,@PayMoneyTrue,@eBankInfo,@Remark,'" + DateTime.Now + "',0)";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID),
				this.conn.CreateParameter("@UserName", DbType.String, UserName),
				this.conn.CreateParameter("@OrderID", DbType.Int32, OrderID),
				this.conn.CreateParameter("@PayNum", DbType.String, PayNum),
				this.conn.CreateParameter("@eBankID", DbType.Int32, eBankID),
				this.conn.CreateParameter("@PayMoney", DbType.Decimal, PayMoney),
				this.conn.CreateParameter("@PayMoneyTrue", DbType.Decimal, PayMoneyTrue),
				this.conn.CreateParameter("@eBankInfo", DbType.String, eBankInfo),
				this.conn.CreateParameter("@Remark", DbType.String, Remark)
			};
			return this.conn.Execute(commandText, parameters) == 1;
		}
		public bool SetPayOK(string PayNum)
		{
			IDbDataParameter dbDataParameter = this.conn.CreateParameter("@PayNum", DbType.String, PayNum);
			return this.conn.Execute("Update HL_PayOnline Set PayStatus=1 Where PayNum=@PayNum", new IDbDataParameter[]
			{
				dbDataParameter
			}) == 1;
		}
		public DataTable GetPayPageByUserID(int pageIndex, int PageSize, int UserID)
		{
			string commandText = "Select top (@PageSize) *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline where OnlinePayID not in (select top (@pageIndex) OnlinePayID from HL_PayOnline where UserID=@UserID Order By OnlinePayID Desc) and UserID=@UserID Order By OnlinePayID Desc";
			IDbDataParameter[] parameters = new IDbDataParameter[]
			{
				this.conn.CreateParameter("@PageSize", DbType.Int32, PageSize),
				this.conn.CreateParameter("@pageIndex", DbType.Int32, (pageIndex - 1) * PageSize),
				this.conn.CreateParameter("@UserID", DbType.Int32, UserID)
			};
			return this.conn.GetDataTable(commandText, parameters);
		}
		public DataTable GetPayPageBySearchCount(int UserID, string Begin, string End, string PayNums)
		{
			string text = "Select *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline Where UserID=@UserID";
			IDbDataParameter[] array = null;
			ArrayList arrayList = new ArrayList();
			arrayList.Add(this.conn.CreateParameter("@UserID", DbType.Int32, UserID));
			if (!string.IsNullOrEmpty(Begin))
			{
				text += " and DateDiff(dd,PayTime, @BeginDate)<=0";
				arrayList.Add(this.conn.CreateParameter("@BeginDate", DbType.DateTime, Begin));
			}
			if (!string.IsNullOrEmpty(End))
			{
				text += " and DateDiff(dd,PayTime, @EndDate)>=0 ";
				arrayList.Add(this.conn.CreateParameter("@EndDate", DbType.DateTime, End));
			}
			if (!string.IsNullOrEmpty(PayNums))
			{
				text += " and PayNum like '%'+@PayNum+'%'";
				arrayList.Add(this.conn.CreateParameter("@PayNum", DbType.String, PayNums));
			}
			text += " Order By OnlinePayID Desc";
			if (arrayList.Count != 0)
			{
				array = new IDbDataParameter[arrayList.Count];
				arrayList.CopyTo(array, 0);
			}
			return this.conn.GetDataTable(text, array);
		}
		public DataTable GetPayPageBySearch(int pageIndex, int PageSize, int UserID, string Begin, string End, string PayNums)
		{
			string text = "Select top (@PageSize) *,(Select PayTitle From HL_OnlinePaySeting Where HL_PayOnline.eBankID=HL_OnlinePaySeting.ID) as eBankName From HL_PayOnline where OnlinePayID not in (select top (@frontpageIndex) OnlinePayID from HL_PayOnline where UserID=@UserID Order By OnlinePayID Desc) and UserID=@UserID ";
			IDbDataParameter[] array = null;
			ArrayList arrayList = new ArrayList();
			arrayList.Add(this.conn.CreateParameter("@PageSize", DbType.Int32, PageSize));
			arrayList.Add(this.conn.CreateParameter("@frontpageIndex", DbType.Int32, (pageIndex - 1) * PageSize));
			arrayList.Add(this.conn.CreateParameter("@UserID", DbType.Int32, UserID));
			if (!string.IsNullOrEmpty(Begin))
			{
				text += " and DateDiff(dd,PayTime, @BeginDate)<=0";
				arrayList.Add(this.conn.CreateParameter("@BeginDate", DbType.DateTime, Begin));
			}
			if (!string.IsNullOrEmpty(End))
			{
				text += " and DateDiff(dd,PayTime, @EndDate)>=0 ";
				arrayList.Add(this.conn.CreateParameter("@EndDate", DbType.DateTime, End));
			}
			if (!string.IsNullOrEmpty(PayNums))
			{
				text += " and PayNum like '%'+@PayNum+'%'";
				arrayList.Add(this.conn.CreateParameter("@PayNum", DbType.String, PayNums));
			}
			text += " Order By OnlinePayID Desc";
			if (arrayList.Count != 0)
			{
				array = new IDbDataParameter[arrayList.Count];
				arrayList.CopyTo(array, 0);
			}
			return this.conn.GetDataTable(text, array);
		}
	}
}
